#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@FileName  :views2.py 
@desc      :
@Author    :Young
@IDE       :PyCharm
@Time      :2021/11/11 0011 21:42
'''

from rest_framework import status
from rest_framework.generics import GenericAPIView
from rest_framework.response import Response


from Admin.adminSerializers import LoginSerializer,AdminSerializer, UserSerializer,ArticlesSerializer,DisGroupSerializer,QuestionsSerializer

from Admin.models import Admin_User,Articles, Questions,\
     Discussion_groups, User

class YuYunDeleteAdminView(GenericAPIView):
    queryset = Admin_User.objects.all()
    serializer_class = AdminSerializer

    def post(self, request,pk):
        #得到pk在数据库进行查询，删除
        deleteAdmin = Admin_User.objects.filter(admin_id=pk)
        deleteAdmin.delete()

        return Response({
            'code':200,
            'msg':'管理员删除成功'
        })

#用户删除
class YuYunDeleteUserView(GenericAPIView):
    queryset = User.objects.all()
    serializer_class = UserSerializer

    def post(self, request,pk):
        deleteUser = User.objects.get(uid=pk)
        # print(User.objects.all()) #有外键不易删除
        # deleteUser.delete()
        print("用户删除成功")

        return Response({
            'code':200,
            'msg':'用户删除成功'
        })

#文章删除,一篇文章的信息
class YuYunDeleteArticleView(GenericAPIView):
    queryset = Articles.objects.all()
    serializer_class = ArticlesSerializer

    def get(self, request,pk):
        print(request)
        current_article = self.get_object()
        print("get",current_article)
        serializer = self.get_serializer(current_article)

        return Response({
            'code':200,
            'msg':'文章详情信息',
            'data':serializer.data
        })

    def post(self, request,pk):

        deleteArticle = Articles.objects.filter(aid=pk)
        # deleteArticle.delete()


        return Response({
            'code':200,
            'msg':'文章删除成功'
        })
#问题删除
class YuYunDeleteQuestionView(GenericAPIView):
    queryset = Questions.objects.all()
    serializer_class = QuestionsSerializer

    def post(self, request,pk):
        # print(pk)
        #得到pk在数据库进行查询，删除
        deleteQuestion = Questions.objects.filter(q_id=pk)
        # deleteQuestion.delete()

        return Response({
            'code':200,
            'msg':'问题删除成功'
        })

#讨论组删除
class YuYunDeleteDisGroupView(GenericAPIView):
    queryset = Discussion_groups.objects.all()
    serializer_class = DisGroupSerializer

    def post(self, request,pk):
        # print(pk)
        #得到pk在数据库进行查询，删除
        deleteDisGroup = Discussion_groups.objects.filter(dis_id=pk)
        # deleteDisGroup.delete()

        return Response({
            'code':200,
            'msg':'讨论组删除成功'
        })


